package fun.chutianshu.eescore_07_aop.mappers;


import fun.chutianshu.eescore_07_aop.entity.Student;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

// 映射类
@Mapper
public interface StudentMapper {
    //根据姓名找学生
    @Select("SELECT * FROM student WHERE stu_name = #{stu_name}")
    @Results({
            @Result(property = "birthday",  column = "birthday", javaType = LocalDate.class)
    })
    List<Student> findByName(@Param("stu_name") String stu_name);

    //所有学生
    @Select("select * from student")
    List<Student> getAll();

    //删除所有学生
    @Delete("delete from student")
    int deleteAll();

    //删除指定学号单个学生
    @Delete("delete from student where stu_code = #{stu_code}")
    int deleteOne(Student student);

    //添加新学生
    @Insert("INSERT INTO student(stu_code, stu_name,stu_gender,college," +
            "profession,grade_num,class_name,stu_id," +
            "phone_num,birthday,photo,weixin_num,department) " +
            "VALUES(#{stu_code}, #{stu_name}, #{stu_gender}, #{college}, " +
            "#{profession}, #{grade_num}, #{class_name}, #{stu_id},  " +
            "#{phone_num}, #{birthday}, #{photo}, #{weixin_num}, #{department})")
    int createOne(Student student);

    //根据学号更改学生信息
    @Update("update student set " +
            "stu_name=#{stu_name}," +
            "stu_gender=#{stu_gender}," +
            "college=#{college}," +
            "profession=#{profession}," +
            "grade_num=#{grade_num}," +
            "class_name=#{class_name}," +
            "phone_num=#{phone_num}," +
            "birthday=#{birthday}," +
            "photo=#{photo}," +
            "weixin_num=#{weixin_num}," +
            "department=#{department} " +
            "where stu_code=#{stu_code}")
    int updateByStuCode(Student student);
}
